<!DOCTYPE html>
<html>
<head>
    <title>Spring Boot WebSocket Chat</title>
</head>
<body>
    <h1>WebSocket Chat</h1>
    <textarea id="messages" cols="30" rows="10" readonly></textarea><br>
    <input type="text" id="messageInput" placeholder="Type a message" />
    <button onclick="sendMessage()">Send</button>
	
    <script type="text/javascript">
		var token = 'test11111';
        var socket = new WebSocket("ws://localhost:8089/ws/chat/token=test11111");

        // WebSocket 连接成功时触发
        socket.onopen = function() {
            console.log("Connected to WebSocket server");
        };

        // 接收到消息时触发
        socket.onmessage = function(event) {
            var messages = document.getElementById("messages");
            messages.value += "Server: " + event.data + "\n";
        };

        // 发送消息
        function sendMessage() {
            var message = document.getElementById("messageInput").value;
            socket.send(message);

            var messages = document.getElementById("messages");
            messages.value += "You: " + message + "\n";
            document.getElementById("messageInput").value = "";
        }
    </script>
</body>
</html>
